home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 010 / ld / ld.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  60 lines

  1. /* List Directory Command by Dave Haynie */
  2. /* Downloaded from the "Well" by Fred Fish */
  3.  
  4.  /* This command is designed to get a simple AmigaDOS directory and
  5.     display it to the screen.  Its also an example of making AmigaDOS 
  6.     filing calls.  Let's see if any of this stuff works.  */
  7.  
  8.  #include <stdio.h>
  9.  #include <ctype.h>
  10.  #include <libraries/dosextens.h>
  11.  
  12.  #define LL 80
  13.  struct FileLock *Lock();  /* Lock doesn't seem declared yet. */
  14.  
  15.  main(argc,argv)
  16.  int argc;
  17.  char *argv[];
  18.  {
  19.     char *dirname;             /* Selected AmigaDOS directory */
  20.     struct FileLock *dir;      /* Locked AmigaDOS directory */
  21.     struct FileInfoBlock *fb;  /* File Info from locked directory */
  22.     BOOL fail;                 /* Directory Access Failure */
  23.     UBYTE count;               /* Line length count */
  24.  
  25.     if (argc == 1)
  26.        dirname = "";
  27.     else if (argc == 2)
  28.        dirname = argv[1];
  29.     else {
  30.        printf("Usage: Ld [dirname]\n");
  31.        Exit();
  32.     }
  33.     fb = (struct FileInfoBlock *) AllocMem(sizeof(struct FileInfoBlock),0);
  34.     dir = Lock(dirname,ACCESS_READ);
  35.     fail = (dir == NULL) | !Examine(dir,fb);
  36.     if (fail) {
  37.        printf("Invalid directory '%s' requested\n",dirname);
  38.        FreeMem(fb,sizeof(struct FileInfoBlock));
  39.        Exit();
  40.     }
  41.     printf("\033[7m\033[3m%s\033[0m\n",fb->fib_FileName);
  42.     ExNext(dir,fb);
  43.     count = 0;
  44.     while (IoErr() != ERROR_NO_MORE_ENTRIES) {
  45.        if (fb->fib_DirEntryType > 0)
  46.           printf("\033[2m%-20s\033[0m",fb->fib_FileName);
  47.        else
  48.           printf("%-20s",fb->fib_FileName);
  49.        count++;
  50.        if (count == 3) {
  51.           printf("\n");
  52.           count = 0;
  53.        }
  54.        ExNext(dir,fb);
  55.     }
  56.     if (count != 0) printf("\n");
  57.     FreeMem(fb,sizeof(struct FileInfoBlock));
  58.     Exit();
  59.  }
  60.